package Chapter17.homework;

/**
 * @author 杨森
 * @date 2022年10月31日 20:43
 */
public class Homework02 {
    public static void main(String[] args) {
        u1 u1 = new u1();
        new Thread(u1).start();
        new Thread(u1).start();

    }
}

class u1 implements Runnable {
    private int num=10000;
    boolean loop=true;


    @Override
    public void run() {
        while (loop){
            synchronized (this){
                if (num<1000){
                    System.out.println("余额不足");
                    break;
                }
                num-=1000;
                System.out.println("线程"+Thread.currentThread().getName()+"钱："+num);

            }

        }
    }
}
